/* ========================================================================= */
/* ------------------------------------------------------------------------- */
/*!
  \file			findwidget.cc
  \date			Dec 2012
  \author		TNick

  \brief		Contains the implementation of FindWidget class


*//*


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Please read COPYING and README files in root folder
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*/
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
//
//
//
//
/*  INCLUDES    ------------------------------------------------------------ */

#include	"findwidget.h"
#include	<cpg/actions/textfield/textfield.h>

/*  INCLUDES    ============================================================ */
//
//
//
//
/*  DEFINITIONS    --------------------------------------------------------- */


/*  DEFINITIONS    ========================================================= */
//
//
//
//
/*  DATA    ---------------------------------------------------------------- */

/*  DATA    ================================================================ */
//
//
//
//
/*  CLASS    --------------------------------------------------------------- */

/* ------------------------------------------------------------------------- */
FindWidget::FindWidget	(
		const QString & s_init, bool with_adv,
		bool with_replace, QWidget * parent )
	: QWidget( parent ), MemTrack()
{
	ui_.setupUi( this );
	if ( with_adv == false )
	{
		ui_.advancedButton->setVisible( false );
	}
	if ( with_replace == false )
	{
		ui_.replaceButtonsWidget->setVisible( false );
	}

	connect( ui_.close, SIGNAL( clicked() ), this, SIGNAL( closeReq() ) );
	connect( ui_.findNextButton, SIGNAL( clicked() ), this, SLOT( findNext() ) );
	connect( ui_.findPreviousButton, SIGNAL( clicked() ), this, SLOT( findPrev() ) );

	connect( ui_.advancedButton, SIGNAL( clicked() ), this, SIGNAL( showAdvanced() ) );
	connect( ui_.replaceAllButton, SIGNAL( clicked() ), this, SLOT( replaceAll() ) );
	connect( ui_.replaceButton, SIGNAL( clicked() ), this, SLOT( replaceOne() ) );
	connect( ui_.replaceNextButton, SIGNAL( clicked() ), this, SLOT( replaceNext() ) );

	connect( ui_.findEdit, SIGNAL( validated(QString) ), this, SLOT( findNext() ) );
	connect( ui_.replaceEdit, SIGNAL( validated(QString) ), this, SLOT( replaceNext() ) );


	setFindText( s_init );
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
FindWidget::~FindWidget	( void )
{
	/* stub */
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void					FindWidget::setFindText		( const QString & s_text )
{
	ui_.findEdit->setFocus();
	ui_.findEdit->setText( s_text );
	ui_.findEdit->selectAll();
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void					FindWidget::findNext		( void )
{
	QString s_find = ui_.findEdit->text();
	if ( s_find.isEmpty() )
	{

		return;
	}
	emit findNext( s_find );
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void					FindWidget::findPrev		( void )
{
	QString s_find = ui_.findEdit->text();
	if ( s_find.isEmpty() )
	{

		return;
	}
	emit findPrev( s_find );
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void					FindWidget::replaceAll		( void )
{
	QString s_find = ui_.findEdit->text();
	if ( s_find.isEmpty() )
	{

		return;
	}
	QString s_repl = ui_.replaceEdit->text();
	emit replaceAll( s_find, s_repl );
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void					FindWidget::replaceOne		( void )
{
	QString s_find = ui_.findEdit->text();
	if ( s_find.isEmpty() )
	{

		return;
	}
	QString s_repl = ui_.replaceEdit->text();
	emit replaceOne( s_find, s_repl );
}
/* ========================================================================= */

/* ------------------------------------------------------------------------- */
void					FindWidget::replaceNext		( void )
{
	QString s_find = ui_.findEdit->text();
	if ( s_find.isEmpty() )
	{

		return;
	}
	QString s_repl = ui_.replaceEdit->text();
	emit replaceNext( s_find, s_repl );
}
/* ========================================================================= */

/*  CLASS    =============================================================== */
//
//
//
//
/* ------------------------------------------------------------------------- */
/* ========================================================================= */
